# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Contributor: Chloe Kudryavtsev <code@toast.bunkerlabs.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=minio
pkgver=0.20240101.163633
# 0.20230324.214123 -> 2023-03-24T21-41-23Z
_pkgver="${pkgver:2:4}-${pkgver:6:2}-${pkgver:8:2}T${pkgver:11:2}-${pkgver:13:2}-${pkgver:15:2}Z"
pkgrel=0
pkgdesc="Open source object storage server compatible with Amazon S3"
url="https://min.io/"
# armhf, armv7, x86: test failures
# riscv64: fails to build cpuinfo module
arch="all !armhf !armv7 !riscv64 !x86"
license="AGPL-3.0-or-later"
makedepends="go"
pkgusers="minio"
pkggroups="minio"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="https://github.com/minio/minio/archive/RELEASE.$_pkgver/minio-$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.logrotate
	"
builddir="$srcdir/$pkgname-RELEASE.$_pkgver"
options="net"

# secfixes:
#   0.20200423-r0:
#     - CVE-2020-11012

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
export CGO_ENABLED=0

build() {
	local prefix='github.com/minio/minio/cmd'
	local date=${_pkgver%%T*}
	local time=${_pkgver#*T}

	go build -tags kqueue -o bin/minio -ldflags "
		-X $prefix.Version=${date}T${time//-/:}
		-X $prefix.CopyrightYear=${date%%-*}
		-X $prefix.ReleaseTag=RELEASE.$_pkgver
		-X $prefix.CommitID=0000000000000000000000000000000000000000
		-X $prefix.ShortCommitID=000000000000
		"
}

check() {
	# Excluded tests:
	# minio/cmd - disk usage errors, doesn't know what btrfs is

	export MINIO_API_REQUESTS_MAX=10000
	# shellcheck disable=2046
	go test -tags kqueue $(go list ./... | grep -v -e 'minio/cmd')
}

package() {
	install -Dm755 "$builddir"/bin/minio -t "$pkgdir"/usr/bin/

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname

	# This file contains secrets.
	install -Dm640 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname

	install -d -m700 -o minio -g minio "$pkgdir"/var/lib/$pkgname
}

cleanup_srcdir() {
	go clean -modcache
	default_cleanup_srcdir
}

sha512sums="
0009cce1d07ccdbcfbd4dcc11b8c1a44dae49ad28bdf792d92adf4fe732e303b39f5756872db176eb95d7a0f71f180f71423762484b36cf29818f593d49b25e1  minio-0.20240101.163633.tar.gz
084373e2f0fd35e0c2c86abbcac3e7611a9931608b3aaf9a76677bc5d2f70944917ae8ad6ec401f989eccf8a5e82891764bb5882624bb48857f85c0ba53ffb83  minio.initd
4710b19471af3d84405b543776d88bf48c9276dd676417f9b6e915e866d934b8e64546aaa5cbfc2a3c23243ec5e4959a1a5b62ba850759b1029f99baa27cbefe  minio.confd
9c6c0f1041989d999b9ff567e8ece29a91e32c98cce9ee6471a7044cce2d8b7b02459753dd593ed6d7eb8bf308abc219c3eb87177e855addd04b286cb60e657f  minio.logrotate
"
